import output from '@/assets/images/device-monitor/xs-dutyOutput.png'
import lowestEfficiency from '@/assets/images/device-monitor/xs-lowestEfficiency.png'
import average from '@/assets/images/device-monitor/xs-averageDuration.png'
import decapitation from '@/assets/images/device-monitor/xs-decapitation.png'
import decapitation1 from '@/assets/images/device-monitor/xs-decapitation1.png'
import efficiency from '@/assets/images/device-monitor/xs-dutyEfficiency.png'
import fallingYarn from '@/assets/images/device-monitor/xs-fallingYarn.png'
import fallingYarn1 from '@/assets/images/device-monitor/xs-fallingYarn1.png'
import energy from '@/assets/images/device-monitor/xs-dutyEnergyConsumption.png'
import breakCntFromLast from '@/assets/images/device-monitor/xs-breakCntFromLast.png'
import brokenEndBoth from '@/assets/images/device-monitor/xs-brokenEndBoth.png'
import averageTime from '@/assets/images/device-monitor/xs-jtpjys.png'
import barrelTotalCnt from '@/assets/images/device-monitor/sm-barrelTotalCnt.png'

const dataBase: any = {
  currentShiftLength: {
    // 细纱 11310
    code: '11310',
    unit: '米',
    title: '当班产量',
    tips: '当班产量：每台细纱车当班产量加起来的总和',
    type: 'number',
    icon: output
  },
  theoreticalYarnWeight: {
    // 粗纱 11410 & 末并 11510 & 预并 11810 & 梳棉 110910
    code: '11410&11510&11810&110910',
    unit: 'kg',
    title: '当班产量',
    tips: '当班产量：每台codeName车当班产量加起来的总和',
    type: 'number',
    icon: output
  },
  currentYarnWeight: {
    // 络筒 11210
    code: '11210',
    unit: 'kg',
    title: '当前产量',
    tips: '',
    type: 'number',
    icon: output
  },
  efcRun: {
    // 络筒 11210
    code: '11210',
    unit: '%',
    title: '平均效率',
    tips: '',
    type: 'number',
    icon: lowestEfficiency
  },
  power: {
    // 细纱 11310 & 粗纱 11410 & 末并 11510 & 预并 11810 & 梳棉 110910
    code: '11310&11410&11510&11810&110910',
    unit: 'kwh',
    title: '当班能耗',
    tips: '当班能耗：每台codeName车当班能耗加起来的总和',
    type: 'number',
    icon: energy
  },
  runEfcAvg: {
    // 细纱 11310
    code: '11310',
    unit: '%',
    title: '当班效率',
    tips: '当班效率=机台运行效率大于1的情况下，细纱机台效率总和的一个平均',
    type: 'percent',
    icon: efficiency
  },
  yxxl: {
    // 细纱实时单锭 11330
    code: '11330',
    unit: '%',
    title: '运行效率',
    tips: ' ',
    type: 'percent',
    icon: efficiency
  },
  breakCntFromLast: {
    // 细纱实时单锭 11330
    code: '11330',
    unit: '个',
    title: '接班断头个数',
    tips: ' ',
    type: 'number',
    icon: breakCntFromLast
  },
  brokenEndBoth: {
    // 细纱实时单锭 11330
    code: '11330',
    unit: '个',
    title: '当前断头/非停车断头',
    tips: '',
    type: 'string',
    icon: brokenEndBoth
  },
  jtpjys: {
    // 细纱实时单锭 11330
    code: '11330',
    unit: '分钟',
    title: '接头平均用时',
    tips: '',
    type: 'minute',
    icon: averageTime
  },
  breakJointTimeAvg: {
    // 细纱 11310
    code: '11310',
    unit: '分钟',
    title: '接头平均用时',
    tips: '接头平均用时：每台细纱车接头平均用时总和的一个平均',
    type: 'second-minute',
    icon: average
  },
  breaksPerKilo: {
    // 细纱 11310
    code: '11310',
    unit: '个',
    title: '千锭时断头',
    tips: '千锭时断头：每台细纱车千锭时断头总和的一个平均',
    type: 'number',
    icon: decapitation
  },
  dqqdsdt: {
    // 细纱实时单锭 11330
    code: '11330',
    unit: '个',
    title: '千锭时断头',
    tips: '',
    type: 'number',
    icon: decapitation1
  },
  doffRate: {
    // 细纱 11310
    code: '11310',
    unit: '%',
    title: '落纱留头率',
    tips: '当班效率=落纱留头率：机台落纱留头率大于1的情况下，细纱机台留头率总和的一个平均',
    type: 'percent',
    icon: fallingYarn
  },
  sclsltl: {
    // 细纱实时单锭 11330
    code: '11330',
    unit: '%',
    title: '落纱留头率',
    tips: '',
    type: 'percent',
    icon: fallingYarn1
  },
  breakCnt: {
    // 粗纱 11410
    code: '11410',
    unit: '次',
    title: '机后断条次数',
    tips: '',
    type: 'number',
    icon: decapitation
  },
  breakYarnCnt: {
    // 粗纱 11410
    code: '11410',
    unit: '次',
    title: '断纱次数',
    tips: '',
    type: 'number',
    icon: decapitation
  },
  onLine: {
    // 末并 11510 & 预并 11810 & 梳棉 110910
    code: '11510&11810&110910',
    unit: '台',
    title: '在线台数',
    tips: '',
    type: 'number',
    icon: decapitation
  },
  offLine: {
    // 末并 11510 & 预并 11810 & 梳棉 110910
    code: '11510&11810&110910',
    unit: '台',
    title: '离线台数',
    tips: '',
    type: 'number',
    icon: decapitation
  },
  passRateBy2Hour: {
    // 细纱-换段预测 113900
    code: '113900',
    unit: '%',
    title: '2小时收敛率',
    tips: '',
    type: 'percent',
    icon: output,
    bgColor: '#ECF2FF'
  },
  passRateBy1Hour: {
    // 细纱-换段预测 113900
    code: '113900',
    unit: '%',
    title: '1小时收敛率',
    tips: '',
    type: 'percent',
    icon: decapitation,
    bgColor: '#E6FFFA'
  },
  passRateByHalfHour: {
    // 细纱-换段预测 113900
    code: '113900',
    unit: '%',
    title: '半小时收敛率',
    tips: '',
    type: 'percent',
    icon: decapitation1,
    bgColor: '#E8F7FF'
  },
  'machineName&efcRunMin': {
    // 络筒 11210
    code: '11210',
    unit: ['号', '%'],
    title: '效率最低机台',
    tips: '',
    type: ['number', 'number'],
    icon: fallingYarn
  },
  spindleNum: {
    // 络筒 11210
    code: '11210',
    unit: '锭',
    title: '总锭数',
    tips: '',
    type: 'number',
    icon: barrelTotalCnt
  },
  runSpindleNum: {
    // 络筒 11210
    code: '11210',
    unit: '锭',
    title: '开车',
    tips: '',
    type: 'number',
    icon: barrelTotalCnt
  },
  parkSpindleNum: {
    // 络筒 11210
    code: '11210',
    unit: '锭',
    title: '停车',
    tips: '',
    type: 'number',
    icon: barrelTotalCnt
  }
}
export const dataRegroup = (data) => {
  const target: any = []
  for (const key in dataBase) {
    let valueKey = [key]
    if (key.includes('&')) {
      // 一个卡片内显示多个数据
      valueKey = key.split('&')
    }
    const val: any = ref([])
    for (let i = 0; i < valueKey.length; i++) {
      const valkey = valueKey[i]
      if (valkey in data) {
        const type = valueKey.length > 1 ? dataBase[key].type[i] : dataBase[key].type
        switch (type) {
          case 'number':
            val.value.push(Math.round(data[valkey]))
            break
          case 'percent':
            val.value.push(Math.round(data[valkey] * 100) / 100)
            break
          case 'second-minute':
            val.value.push(Math.round((data[valkey] / 60) * 100) / 100)
            break
          case 'minute':
            val.value.push(Math.round(data[valkey]))
            break
          case 'string':
            val.value.push(data[valkey])
        }
      }
    }

    dataBase[key].value = val.value
    target.push(dataBase[key])
  }
  console.log(target)
  return target
}

export const shortcuts = [
  {
    text: '近三天',
    value: () => {
      const end = new Date()
      const start = new Date()
      start.setTime(start.getTime() - 3600 * 1000 * 24 * 3)
      return [start, end]
    }
  },
  {
    text: '近一周',
    value: () => {
      const end = new Date()
      const start = new Date()
      start.setTime(start.getTime() - 3600 * 1000 * 24 * 7)
      return [start, end]
    }
  },
  {
    text: '近1个月',
    value: () => {
      const end = new Date()
      const start = new Date()
      start.setTime(start.getTime() - 3600 * 1000 * 24 * 30)
      return [start, end]
    }
  }
]

// 粗细联工序 获取名称
export const handleRailStateName = (num) => {
  if (num == 0) {
    return ['无', '#868484']
  } else if (num == 1) {
    return ['轨道停用', '#71797B']
  } else if (num == 2) {
    return ['空轨道', '#C4C7CE']
  } else if (num == 3) {
    return ['满纱', '#43C265']
  } else if (num == 4) {
    return ['空管', '#FFC62E']
  } else if (num == 5) {
    return ['满纱入库中', '#49BEFF']
  } else if (num == 6) {
    return ['空管入库中', '#49BEFF']
  } else if (num == 7) {
    return ['满纱出库中', '#49BEFF']
  } else if (num == 8) {
    return ['空管出库中', '#49BEFF']
  } else if (num == 10) {
    return ['等待进空管', '#49BEFF']
  } else if (num == 11) {
    return ['等待进尾纱', '#49BEFF']
  } else if (num == 12) {
    return ['等待进满纱', '#49BEFF']
  } else if (num == 14) {
    return ['尾纱管', '#E74FEC']
  } else if (num == 15) {
    return ['尾纱入库中', '#49BEFF']
  } else if (num == 16) {
    return ['尾纱出库中', '#49BEFF']
  } else if (num == 20) {
    return ['状态错误', '#fa0f0f']
  } else {
    return ['无', '#868484']
  }
}
